/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2025-04-02 14:45:40
 * @LastEditors: jqm123 2289662078@qq.com
 * @LastEditTime: 2025-09-02 20:27:30
 * @FilePath: vue.config.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
"use strict";
const path = require("path");
const defaultSettings = require("./src/settings");
const TerserPlugin = require("terser-webpack-plugin");
function resolve(dir) {
  return path.join(__dirname, dir);
}
const CompressionPlugin = require("compression-webpack-plugin");
const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i;
const port = process.env.port || process.env.npm_config_port || 9000;
const name = defaultSettings.title || "安心修";
module.exports = {
  publicPath: "./",
  outputDir: "dist",
  assetsDir: "static",
  lintOnSave: false,
  productionSourceMap: false,
  devServer: {
    port: port,
    open: false,
    hot: true,
    // host: "192.168.31.183",
    proxy: {
      "/api": {
        target: process.env.VUE_APP_BASE_API, // 本地api地址
        changeOrigin: true,
        pathRewrite: {
          "^/api": "/api",
        },
      },
    },
  },
  configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    name: name,

    resolve: {
      modules: [path.resolve("node_modules"), "node_modules"],
      alias: {
        "@": resolve("src"),
      },
    },
    entry: "./src/main.js",
    optimization: {
      minimize: true,
      minimizer: [
        new TerserPlugin({
          test: /\.js(\?.*)?$/i,
          parallel: true,
        }),
      ],
    },
  },
  chainWebpack(config) {
    config.plugins.delete("compression"); // 禁用默认压缩插件
    // config.plugin("html").tap((args) => {
    //   args[0].title = name;
    //   return args;
    // });
    // if (process.env.NODE_ENV === "production") {
    //   config.plugin("compressionPlugin").use(
    //     new CompressionPlugin({
    //       filename: "[path][base].gz[query]",
    //       algorithm: "gzip",
    //       test: productionGzipExtensions,
    //       threshold: 10240,
    //       minRatio: 0.8,
    //     })
    //   );
    // }
  },
  css: {
    loaderOptions: {
      less: {
        lessOptions: {
          modifyVars: {
            "@tabbar-item-font-size": "30px",
            "grid-item-content-background-color": "transparent",
            "field-placeholder-text-color": "#000",
          },
          javascriptEnabled: true,
        },
      },
    },
  },
};
